<?php


namespace app\http\middleware;
use app\admin\model\Menu;
use app\admin\model\OperateLog;
use app\Request;


class MerchantLog
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle(Request $request, \Closure $next,$name)
    {
        $response = $next($request);
        $url = request()->controller().'/'.request()->action();
        $menuModel = new Menu();
        //$menuInfo = $menuModel->where(['path' => $url])->find();
        if ($request->method() =='POST'){ // 用户 修改的时候做记录
            $data =
                [
                    'operate_id' => $request->staff_account['id'],
                    'user_type' => '2',
                    'route' => $url,
                    'name' =>$name,
                    'method' => $request->method(),
                    'req_data' => json_encode($request->param()),
                    'create_time' => time(),
                    'ip' => $request->ip(),
                ];
            $operateLogModel = new OperateLog();
            $operateLogModel->insert($data);

        }
        return $response;
    }
}